#include <cstdlib>
#include <iostream>
#include <conio.h>

//using namespace std;

typedef struct hex{
    int side[6];
    int ID;
};

void rotate_hex(hex *h);
void read_wheel(int mz);
int dir;
int prev_mz=0;

int main(int argc, char *argv[]){
    hex h = {{0, 1, 2, 3, 4, 5}, 1};
    int r;
    for (int i = 0; i < 6; i++){
        printf("array[%d]: %d\n", i, h.side[i]);
    }
    do {
        r=getch();
        read_wheel(r);

        rotate_hex(&h);
        for (int i = 0; i < 6; i++){
            printf("array[%d]: %d\n", i, h.side[i]);
        }
        printf("\n");
    } while (r != 'q');
}

void read_wheel(int mz){
    if (mz == 'w'){
        dir = dir-1;
    }
    else if (mz == 's'){
        dir = dir+1;
    }
    else dir = dir;
}

void rotate_hex(hex *h){
    int temp;

    if (dir > prev_mz ) {
        temp = h->side[5];
        for(int i=5; i>0; i--){
            h->side[i] = h->side[i-1];
        }
        h->side[0] = temp;
    }
    else if (dir < prev_mz){
        temp = h->side[0];
        for(int i=0; i<5; i++){
            h->side[i] = h->side[i+1];
        }
        h->side[5] = temp;
    }
    prev_mz = dir;
}
